﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 问卷题目 数据类
    /// </summary>
    public class PaperTopic
    {
        public PaperTopic()
        {
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(decimal paperId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FPaperId,FTopic,FTopicType,FPaperTopicId,FStdAnswer,FShortAnswerCount,FPubDate,FPubDeptNo,FPubEmpNo,FPubIp ");
            strSql.Append(" FROM t_PaperTopic ");
            strSql.Append(" WHERE FPaperId=@FPaperId");

            SqlParameter[] parameters = {
					new SqlParameter("@FPaperId", SqlDbType.Decimal,9)
                                        };
            parameters[0].Value = paperId;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_DSJCJ.Model.PaperTopic GetModel(decimal paperTopicId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FPaperId,FTopic,FTopicType,FPaperTopicId,FStdAnswer,FShortAnswerCount,FPubDate,FPubDeptNo,FPubEmpNo,FPubIp from t_PaperTopic ");
            strSql.Append(" where FPaperTopicId=@FPaperTopicId");
            SqlParameter[] parameters = {
					new SqlParameter("@FPaperTopicId", SqlDbType.Decimal)
			};
            parameters[0].Value = paperTopicId;

            ElingOA6_DSJCJ.Model.PaperTopic model = new ElingOA6_DSJCJ.Model.PaperTopic();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-09-12</date>
        /// </summary>
        public ElingOA6_DSJCJ.Model.PaperTopic DataRowToModel(DataRow row)
        {
            ElingOA6_DSJCJ.Model.PaperTopic model = new ElingOA6_DSJCJ.Model.PaperTopic();
            if (row != null)
            {
                if (row["FPaperId"] != null && row["FPaperId"].ToString() != "")
                {
                    model.FPaperId = decimal.Parse(row["FPaperId"].ToString());
                }
                if (row["FTopic"] != null)
                {
                    model.FTopic = row["FTopic"].ToString();
                }
                if (row["FTopicType"] != null)
                {
                    model.FTopicType = row["FTopicType"].ToString();
                }
                if (row["FPaperTopicId"] != null && row["FPaperTopicId"].ToString() != "")
                {
                    model.FPaperTopicId = decimal.Parse(row["FPaperTopicId"].ToString());
                }
                if (row["FStdAnswer"] != null)
                {
                    model.FStdAnswer = row["FStdAnswer"].ToString();
                }
                if (row["FShortAnswerCount"] != null && row["FShortAnswerCount"].ToString() != "")
                {
                    model.FShortAnswerCount = int.Parse(row["FShortAnswerCount"].ToString());
                }
                if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                {
                    model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                }
                if (row["FPubDeptNo"] != null)
                {
                    model.FPubDeptNo = row["FPubDeptNo"].ToString();
                }
                if (row["FPubEmpNo"] != null)
                {
                    model.FPubEmpNo = row["FPubEmpNo"].ToString();
                }
                if (row["FPubIp"] != null)
                {
                    model.FPubIp = row["FPubIp"].ToString();
                }
            }
            return model;
        }
    }
}
